package com.wpp.interceptor;

import com.wpp.constant.SessionConstant;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession(true);
        Object userName = session.getAttribute(SessionConstant.SESSION_USER_NAME);
        if (null != userName) {
            return true;
        } else {
            response.sendRedirect(request.getContextPath() + "/login/api/toLogin");
            return false;
        }
    }
}
